import 'package:sqflite/sqlite_api.dart';

import 'manager/db_provider.dart';

class PraiseDao extends BaseDbProvider {
  ///表名
  final String tabName = "gk_priaise";

  ///主表字段
  final String columnId = "_id";

  @override
  tableName() {
    return tabName;
  }

  @override
  tableSqlString() {
    return tableBaseString(tabName, columnId) + "topicId text)";
  }

  ///插入一条点赞过的话题ID
  Future insert(String topicId) async {
    Database db = await getDataBase();
    Map<String, dynamic> map = Map();
    map["topicId"] = topicId;
    return await db.insert(tabName, map);
  }

  Future<Set<String>> queryAll() async {
    Database db = await getDataBase();
    List<Map<String, dynamic>> maps = await db.query(tabName);
    Set<String> result = Set();
    maps.forEach((map) {
      result.add(map["topicId"]);
    });
    return result;
  }

  ///删除点赞
  Future delPraise(String topicId) async {
    Database db = await getDataBase();
    return await db.delete(tabName, where: "topicId = ?", whereArgs: [topicId]);
  }
}
